package ssw.gui.japplet;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import ssw.game.GameResults;

public class NormalRoundJPanel extends JPanel implements ActionListener {
	private final AppCore bridge;

	private final JTextArea taCorrect = new JTextArea();
	private final JTextArea taMissed = new JTextArea();
	private final JTextArea taWrong = new JTextArea();
	
	private final JButton btnDone = new JButton("Done");
	
	public NormalRoundJPanel(AppCore appCore) {
		super(new GridBagLayout());
		bridge = appCore;
		initComponents();
	}

	private void initComponents() {
		GridBagConstraints gbc = null;
		int y = 0;

		gbc = new GridBagConstraints();
		gbc.gridy = y;
		gbc.gridx = 0;
		add(new JLabel("Correct: "), gbc);

		gbc = new GridBagConstraints();
		gbc.gridy = y;
		gbc.gridx = 1;
		add(taCorrect, gbc);

		y++;
		
		gbc = new GridBagConstraints();
		gbc.gridy = y;
		gbc.gridx = 0;
		add(new JLabel("Missed: "), gbc);

		gbc = new GridBagConstraints();
		gbc.gridy = y;
		gbc.gridx = 1;
		add(taMissed, gbc);

		y++;
		
		gbc = new GridBagConstraints();
		gbc.gridy = y;
		gbc.gridx = 0;
		add(new JLabel("Wrong: "), gbc);
		
		gbc = new GridBagConstraints();
		gbc.gridy = y;
		gbc.gridx = 1;
		add(taWrong, gbc);

		y++;
		
		
		gbc = new GridBagConstraints();
		gbc.gridy = y;
		gbc.gridx = 0;
		gbc.gridwidth = 2;
		add(btnDone, gbc);
		
		btnDone.addActionListener(this);
	}	
	
	public void setup(GameResults results) {
		taCorrect.setText(results.getCorrect().toString());
		taMissed.setText(results.getMissed().toString());
		taWrong.setText(results.getWrong().toString());
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		bridge.nextRound();
	}
}
